/**
 * 封装log4js
 */

const log4js = require('log4js')

const levels = {
  'trace': log4js.levels.TRACE,
  // log4js.levels.DEBUG,
  // log4js.levels.INFO: Level;
  // log4js.levels.WARN: Level;
  // log4js.levels.ERROR: Level;
  // log4js.levels.FATAL: Level;
}

log4js.configure({
  appenders: {
    out: { type: "stdout" },
    app: { type: "file", filename: "logs/app.log" },
    everything: {
      type: "dateFile",
      filename: "logs/errors.log",
      pattern: ".yyyy-MM-dd-hh",
      // compress: true,
      alwaysIncludePattern: true,
    },
  },
  categories: {
    default: { appenders: ["out"], level: "info" },
    error: { appenders: ["out", "app", "everything"], level: "error" },
    debug: { appenders: ["out", "app"], level: "debug" },
  },
})

exports.debug = (content) => {
  let logger = log4js.getLogger("debug")
  logger.level = "debug"
  logger.debug(content)
}

exports.info = (content) => {
  let logger = log4js.getLogger();
  logger.level = "info"
  logger.info(content);
}

exports.error = (content) => {
  let logger = log4js.getLogger("error");
  logger.level = "error"
  logger.error(content);
};